package br.edu.ifrn.sgpapp.rest;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import br.edu.ifrn.sgp.dtos.ProcessoDTO;

public class ProcessoREST {
	
	public static List<ProcessoDTO> listarProcessosUsuario(int idUsuario) throws RestClientException {
		
		String url = Enderecos.URL_PRINCIPAL_SGP + "processo/processosUsuario?idUsuario="+idUsuario;
		
		RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
        
        ProcessoDTO[] procs = restTemplate.getForObject(url, ProcessoDTO[].class);
        
        List<ProcessoDTO> resultado = new ArrayList<ProcessoDTO>();
        
        if (procs != null){
        	resultado = Arrays.asList(procs);
        }
		
		return resultado;
	}
	
	public static ProcessoDTO recuperarDetalhesProcesso(int idProcesso) throws RestClientException {
		
		String url = Enderecos.URL_PRINCIPAL_SGP + "processo?idProcesso="+idProcesso;
		
		RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
        
		return restTemplate.getForObject(url, ProcessoDTO.class);
	}
	
}
